package oop_homework_2;

import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

import org.junit.Test;

import homework.reverseSort;
/*
 * 2、编写程序，模拟银行账户功能。要求如下：
 *属性：账号（account）、储户姓名(name)、地址(address)、存款余额(balance)、最小余额(minBalance)
 *方法：存款(deposit)、取款(withdraw)、查询(query)
 *根据用户操作显示储户相关信息。
 *如存款操作后，显示储户原有余额、今日存款数额及最终存款余额；
 *取款时，若最后余额小于最小余额，拒绝取款，并显示“至少保留余额：XXX”
 * */
public class BankDemo {
	public static void main(String[] args) {
		Set<Bankaccount> bankaccountsset = new HashSet<>();
		Option(bankaccountsset);		
	}
	public static void Option(Set<Bankaccount> bankaccountsset) {
		Scanner input = new Scanner(System.in);
		while(true){
			System.out.println("请选择您的操作：");
			System.out.println("1.创建账户");
			System.out.println("2.查询");
			System.out.println("3.存款");
			System.out.println("4.取款");
			int choose = input.nextInt();
			switch (choose) {
			case 1:
				CreateAccount(bankaccountsset);
				break;
			case 2:
				System.out.println("请输入您想要查询的账号：");
				int searchaccount = input.nextInt();
				for (Bankaccount bankaccount : bankaccountsset) {
					if (bankaccount.getAccount() == searchaccount) {
						bankaccount.query();
					}
				}
				break;
			case 3:
				System.out.println("请输入您想要操作的账号：");
				int searchaccount2 = input.nextInt();
				for (Bankaccount bankaccount : bankaccountsset) {
					if (bankaccount.getAccount() == searchaccount2) {
						System.out.println("请输入存入金额：");
						int deal = input.nextInt();
						bankaccount.deposit(deal);
					}
				}
				break;
			case 4:
				System.out.println("请输入您想要操作的账号：");
				int searchaccount3 = input.nextInt();
				for (Bankaccount bankaccount : bankaccountsset) {
					if (bankaccount.getAccount() == searchaccount3) {
						System.out.println("请输入取出金额：");
						int deal = input.nextInt();
						bankaccount.withdraw(deal);
					}
				}
				break;

			default:
				break;
			}
		}
	}
	/*
	 * 创建用户方法
	 * */
	@Test
	public static void CreateAccount(Set<Bankaccount> bankaccountsset) {
		//Set<Bankaccount> bankaccountsset = new HashSet<>();
		Scanner input = new Scanner(System.in);
		while(true){
			System.out.println("请输入账号：");	
			int account = 0;
			account = input.nextInt();
			for (Bankaccount bankaccount : bankaccountsset) {
				if (bankaccount.getAccount() == account) {
					System.out.println("账号已存在！请重新创建！");
					return;
				}
			}
			System.out.println("请输入姓名：");
			String name = input.next();
			System.out.println("请输入地址：");
			String address = input.next();
			System.out.println("请输入余额：");
			double balance = input.nextDouble();
			Bankaccount bankaccount = new Bankaccount(account, name, address, balance);
			bankaccountsset.add(bankaccount);
			for (Bankaccount bankaccount1 : bankaccountsset) {
				System.out.println(bankaccount1);
			}
			System.out.println("是否继续创建？ 1.是  2.否");
			int choose = input.nextInt();
			if(choose == 1){
				continue;
			}else if (choose == 2) {
				break;
			}
		}
	}
}
